from PyQt5.QtWidgets import QApplication, QWidget, QLineEdit, QVBoxLayout, QTextEdit
from PyQt5.QtCore import *
from PyQt5.QtGui import QIcon
import sys


def init_widget(w: QWidget):
    # 修改窗口标题
    w.setWindowTitle('单行输入框')
    # 设置窗口大小
    w.resize(480, 320)

    layout = QVBoxLayout()
    """------------------ 展示单行输入框 ------------------"""
    edit = QLineEdit()
    # 设置输入框提示
    edit.setPlaceholderText('请输入用户名')
    # 设置文本
    edit.setText('张三')
    # 获取单选框的文字
    text = edit.text()
    print(text)
    # 设置输入框最大字符数
    edit.setMaxLength(10)
    layout.addWidget(edit)

    edit_pwd = QLineEdit("Password")
    edit_pwd.setPlaceholderText('请输入密码')
    edit_pwd.setEchoMode(QLineEdit.Password)
    layout.addWidget(edit_pwd)

    """------------------ 展示多行输入框 ------------------"""
    text_edit = QTextEdit()
    # 设置提示内容
    text_edit.setPlaceholderText('请输入个人介绍')
    # 设置文本内容
    text_edit.setPlainText('个人介绍')
    # 获取输入的内容
    print(text_edit.toPlainText())
    text_edit.clear()
    layout.addWidget(text_edit)

    w.setLayout(layout)


if __name__ == '__main__':
    # 1.创建应用程序
    app = QApplication(sys.argv)
    # 2.创建窗口
    w = QWidget()

    init_widget(w)

    # 3.显示窗口
    w.show()

    # 4.等待窗口停止
    sys.exit(app.exec())
